<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */

class Default_Model_Setting extends Zend_Db_Table{
	
	protected $_name    = "settings";
    protected $_primary = "id";
    
    public function getSetting($name){
    	if($this->checkSettingExists($name)){
    	   $db = Zend_Registry::get('db');
            $db->setFetchMode(Zend_Db::FETCH_ASSOC);
            
            $select = $db->select()
                        ->from(array('s' => 'settings'), array('value'))
                        ->where('s.name = ?', $name);
            
            $result = $db->fetchRow($select);
            
            return current($result);
    	}
        
        return false;
    }
    
    public function checkSettingExists($name){
    	$option = array('table' => 'settings', 'field' => 'name');
    	$validator = new Zend_Validate_Db_RecordExists($option);
        
        if($validator->isValid($name)){
            return true;
        }
        
        return false;
    }
}